package com.venus.mapper;

import com.venus.entity.Menu;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.LinkedHashMap;
import java.util.List;

/**
 * Created by admin on 28/6/17.
 */
public interface MenuMapper {

	/**
	 * 查询所有一级node
	 * @return
	 */
	@Select("select id, name from menu where p_id=0")
	List<Menu> getAllParentNodeInfo();

	/**
	 * 添加菜单
	 * @return
	 */
	@Insert("insert into menu(p_id,name,url,is_used) values(#{menu.pId},#{menu.name},#{menu.url},#{menu.isUsed})")
	void addMenu(@Param("menu") Menu menu);

	/**
	 * 分页查询菜单列表
	 * @param menu
	 * @return
	 */
	List<Menu> findMenus(Menu menu);

	/**
	 * 更新菜单
	 * @param menu
	 */
	void updateMenu(Menu menu);

	/**
	 * 查询所有菜单
	 * @return
	 */
	@Select("select id,p_id pid,name ,url from menu where is_used = 'y'")
	List<LinkedHashMap<String,String>> findAllMenus();

	/**
	 * 根据菜单id查询菜单信息
	 * @param id
	 * @return
	 */
	@Select("select id ,p_id as pId, name , url , is_used as isUsed from menu where id = #{id}")
	Menu findMenuInfoById(@Param("id") int id );
}
